<div class="flex flex-wrap space-y-4 md:flex-nowrap md:space-y-0">
  <%= render 'shared/settings_nav' %>
  <div class="flex-grow max-w-xl mx-auto">
    <h1 class="text-4xl font-bold mb-4">Account</h1>
    <%= form_for '', url: settings_account_path, method: :patch, html: { autocomplete: 'off', class: 'space-y-4' } do |f| %>
      <%= f.fields_for current_account do |ff| %>
        <div class="form-control">
          <%= ff.label :name, 'Company Name', class: 'label' %>
          <%= ff.text_field :name, required: true, class: 'base-input', dir: 'auto' %>
        </div>
        <div class="grid md:grid-cols-2 gap-4">
          <div class="form-control">
            <%= ff.label :timezone, class: 'label' %>
            <%= ff.select :timezone, nil, {}, class: 'base-select' do %>
              <%= time_zone_options_for_select(current_account.timezone) %>
            <% end %>
          </div>
          <div class="form-control">
            <%= ff.label :locale, 'Time format', class: 'label' %>
            <%= ff.select :locale, options_for_select(controller.class::LOCALE_OPTIONS.invert, current_account.locale), {}, class: 'base-select' %>
          </div>
        </div>
      <% end %>
      <% encrypted_config = @encrypted_config || EncryptedConfig.find_or_initialize_by(account: current_account, key: EncryptedConfig::APP_URL_KEY) %>
      <% if !Docuseal.multitenant? && can?(:manage, encrypted_config) && !current_account.testing? %>
        <%= f.fields_for encrypted_config do |ff| %>
          <div class="form-control">
            <%= ff.label :value, 'App URL', class: 'label' %>
            <%= ff.text_field :value, autocomplete: 'off', class: 'base-input' %>
          </div>
        <% end %>
      <% end %>
      <% if can?(:update, current_account) %>
        <div class="form-control pt-2">
          <%= f.button button_title(title: 'Update', disabled_with: 'Updating'), class: 'base-button' %>
        </div>
      <% end %>
    <% end %>
    <% if can?(:manage, AccountConfig) %>
      <div class="px-1 mt-8">
        <h2 class="text-2xl font-bold mb-2">Preferences</h2>
        <% account_config = AccountConfig.find_or_initialize_by(account: current_account, key: AccountConfig::FORCE_MFA) %>
        <% if can?(:manage, account_config) %>
          <%= form_for account_config, url: account_configs_path, method: :post do |f| %>
            <%= f.hidden_field :key %>
            <div class="flex items-center justify-between py-2.5">
              <span>
                Force 2FA with Authenticator App
              </span>
              <%= f.check_box :value, class: 'toggle', checked: account_config.value, onchange: 'this.form.requestSubmit()' %>
            </div>
          <% end %>
        <% end %>
        <% account_config = AccountConfig.find_or_initialize_by(account: current_account, key: AccountConfig::ALLOW_TYPED_SIGNATURE) %>
        <% if can?(:manage, account_config) %>
          <%= form_for account_config, url: account_configs_path, method: :post do |f| %>
            <%= f.hidden_field :key %>
            <div class="flex items-center justify-between py-2.5">
              <span>
                Allow typed text signatures
              </span>
              <%= f.check_box :value, class: 'toggle', checked: account_config.value != false, onchange: 'this.form.requestSubmit()' %>
            </div>
          <% end %>
        <% end %>
        <% account_config = AccountConfig.find_or_initialize_by(account: current_account, key: AccountConfig::ALLOW_TO_RESUBMIT) %>
        <% if can?(:manage, account_config) %>
          <%= form_for account_config, url: account_configs_path, method: :post do |f| %>
            <%= f.hidden_field :key %>
            <div class="flex items-center justify-between py-2.5">
              <span>
                Allow to resubmit completed forms
              </span>
              <%= f.check_box :value, class: 'toggle', checked: account_config.value != false, onchange: 'this.form.requestSubmit()' %>
            </div>
          <% end %>
        <% end %>
      </div>
    <% end %>
    <% if can?(:manage, current_account) && Docuseal.multitenant? && true_user == current_user %>
      <div class="px-1 mt-8">
        <h2 class="text-2xl font-bold mb-2">Danger Zone</h2>
        <%= button_to button_title(title: 'Delete my account'), settings_account_path, class: 'btn btn-outline btn-error block', data: { turbo_confirm: 'Schedule account for deletion?' }, method: :delete, id: :account_delete_button %>
      </div>
    <% end %>
  </div>
  <div class="w-0 md:w-52"></div>
</div>
